package com.rgs.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: com-rgs-parent
 * @description: Exchange交换机为 Fanout模式，该模式不需要routing key
 * @author: Mr.Ren
 * @create: 2023-01-06 13:36
 **/
@Configuration
public class FanoutRabbitConfig {

    /**
     * 队列A
     *
     * @return
     */
    @Bean
    public Queue fanoutExchangeQueueA() {
        return new Queue(RabbitMQConfig.RABBITMQ_FANOUT_QUEUE_A, true, false, false);
    }

    /**
     * 队列B
     *
     * @return
     */
    @Bean
    public Queue fanoutExchangeQueueB() {
        return new Queue(RabbitMQConfig.RABBITMQ_FANOUT_QUEUE_B, true, false, false);
    }

    /**
     * 交换机Exchange
     *
     * @return
     */
    @Bean
    public FanoutExchange rabbitmqDemoFanoutExchange() {
        return new FanoutExchange(RabbitMQConfig.RABBITMQ_DEMO_FANOUT_EXCHANGE, true, false);
    }

    /**
     * 队列A绑定交换机，不需要指定路由
     *
     * @return
     */
    @Bean
    public Binding bindFanoutA() {
        return BindingBuilder
                .bind(fanoutExchangeQueueA())
                .to(rabbitmqDemoFanoutExchange());
    }

    /**
     * 队列B绑定交换机，不需要指定路由
     *
     * @return
     */
    @Bean
    public Binding bindFanoutB() {
        return BindingBuilder
                .bind(fanoutExchangeQueueB())
                .to(rabbitmqDemoFanoutExchange());
    }


    public static void main(String[] args) {
        String s1 = null;
        String s2 = "111";
        System.out.println(s1+s2);
    }
}
